//
//  RadioControl.m
//  iPhoneControlApplication
//
//  Created by Elliot Chapple on 11/04/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "RadioControl.h"


@implementation RadioControl

//Synth all objects
@synthesize freqUp;
@synthesize freqDown;
@synthesize currentFrequency;
@synthesize radioStationName;
@synthesize amFMSwitch;
@synthesize amFMLabel;
@synthesize scanButton;
@synthesize stored1;
@synthesize stored2;
@synthesize stored3;
@synthesize stored4;

//Methods

//To change the frequency up
-(IBAction)freqUpButtonPress
{
	NSString *currentValue = currentFrequency.text;
	int newValue = [currentValue intValue];
	newValue = newValue + 1;
	NSString *updatedvalue = [[NSString alloc] initWithFormat:@"%d", newValue];
	currentFrequency.text = updatedvalue;
	[updatedvalue release];
}

//To change the frequency down
-(IBAction)freqDownButtonPress
{
	NSString *currentValue = currentFrequency.text;
	int newValue = [currentValue intValue];
	newValue = newValue - 1;
	NSString *updatedvalue = [[NSString alloc] initWithFormat:@"%d", newValue];
	currentFrequency.text = updatedvalue;
	[updatedvalue release];
}

//Switch to AM or FM radio
-(IBAction)amFMSwitchOver
{
	NSString *currentValue = amFMLabel.text;
	if (currentValue == @"AM") amFMLabel.text = @"FM";
	else amFMLabel.text = @"AM";
}

//Scan Through Radio Stations
-(IBAction)scanRadioStations
{
	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Continue Scan?" delegate:self cancelButtonTitle:@"Cancel Scanning" destructiveButtonTitle:@"Scan Radio Stations" otherButtonTitles:nil];
	[actionSheet showInView:self.view];
	[actionSheet release];
}


//Store a radio station corresponding to the button pressed
-(IBAction)storeStation:(id)sender
{
	NSString *title = [sender titleForState:UIControlStateNormal];
	//bit to store freq label
	NSString *currentLabel = radioStationName.text;
	NSString *newText = [[NSString alloc] initWithFormat:@"%@ saved in button %@.", currentLabel, title];
	
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Radio Station Saved" message:newText delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
	[newText release];
	
}




//Apple Standard Code - preserved for futre interactions/improvements

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}


@end
